
include std/unittest.e
include qt/core.e as qt
include std/io.e

--~ set_test_verbosity(TEST_SHOW_ALL)

function OnQuit()
		abort(0)
	return 0
end function
object _ =  qt:init()
atom
	--this can be a machine exception -1 if file doesn't exist
	--probably is a bad form to use especially in a test
	w  = qt:loadUi(read_file("test.ui")),
	b  = qt:findChild(w, "pushButton")

test_not_equal("connectpushButton clicked", 0
    ,qt:connect(b, "clicked()", "slot()", routine_id("OnQuit"))  )

test_equal("is pushButton", 1 ,inherits(b, "QPushButton")  )


test_not_equal("connectcheckBox stateChanged", 0
    ,qt:connect({w, "checkBox"}, "stateChanged(int)", "slot(int)", routine_id("OnQuit"))  )

test_equal("connectcheckBox lot", 0
    ,qt:connect({w, "checkBox"}, "stateChanged(int)", "lot(int)", routine_id("OnQuit"))  )

test_not_equal("findChild QAction a", 0, qt:findChild(w, "actionOpenFile", "QAction") )
test_equal("findChild QAction a", 0, qt:findChild(w, "actionOpenFile") )
object a =  qt:findChild(w, "actionOpenFile", "QAction")
--~ test_not_equal("connectQAAction activated", 0
    --~ ,qt:connect(a, "activated()", "slot()", routine_id("OnQuit"))  )

test_not_equal("connectQAAction triggered", 0
    ,qt:connect(a, "triggered()", "slot()", routine_id("OnQuit"))  )

test_equal("connectQAAction timeout", 0
    ,qt:connect(a, "timeout()", "slot()", routine_id("OnQuit"))  )
--~ test_not_equal("{}connectQAAction activated", 0
    --~ ,qt:connect({w, "actionOpenFile", "QAction"}, "activated()", "slot()", routine_id("OnQuit"))  )
test_not_equal("{}connectQAAction triggered", 0
    ,qt:connect({w, "actionOpenFile", "QAction"}, "triggered()", "slot()", routine_id("OnQuit"))  )


test_equal("propset b text ello", 1, qt:propset(b, "text", "ello") )
test_equal("propget b text ", "ello", qt:propget(b, "text") )

--need to pass back and accept sequences for some properties
-- have fixed propget for QPoint and QSize
test_equal("propget_struct b size ",  "{317,20}", qt:propget_struct(b, "size") )
qt:resize(b, 14, 16)
test_equal("propget_struct b size ",  "{14,16}", qt:propget_struct(b, "size") )

test_equal("propget_struct b pos ",  "{9,367}", qt:propget_struct(b, "pos") )
qt:move(b, 11, 12)
test_equal("propget_struct b pos ", "{11,12}", qt:propget_struct(b, "pos") )


test_equal("propget_struct b geometry ", "{11,12,14,16}", qt:propget_struct(b, "geometry") )
--~ test_equal("propget_struct b normalGeometry ", "{11,12,14,16}", qt:propget_struct(b, "normalGeometry") )
test_equal("propget_struct b text ", "ello", qt:propget_struct(b, "text") )

--these will crash as expected, probably shoulc make a will crash test
--~ test_equal("propget_struct 0 pos ", 1, qt:propget_struct(0, "pos") )
--~ test_equal("propget_struct b ops ", 1, qt:propget_struct(b, "ops") )

--this propset visable works the same as show()
--~ qt:propset(w, "visible" , 1)

--for some reason showing this widget crashes
--too much mucking around with the properties?
--~ qt:show(w)

--not sure how to automate testing this one
--~ qt_setTabOrder()
--~ widget_info(w)  

test_report()

--~ _ = qt:run()

